﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SES.CMS.DO;
using SES.CMS.BL;

namespace SES.CMS
{
    public partial class ClientSite: MasterPage
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            Response.Cache.SetNoServerCaching();
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetNoStore();
            Response.Cache.SetExpires(new DateTime(1900, 01, 01, 00, 00, 00, 00));
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["TenDN"] != null)
            {
                hplLogin.Visible = true;
                lblLogin.Visible = false;
                lblLoginName.Text = Session["ClientName"].ToString();
            }
            else
            {
                hplLogin.Visible = false;
                lblLogin.Visible = true;
                lblLoginName.Text = "";
            }

        }

        protected void lnkTiengViet_Click(object sender, EventArgs e)
        {
            Changelang("VN");
        }
        protected void lnkEnglish_Click(object sender, EventArgs e)
        {
            Changelang("EN");
        }
        private void Changelang(string nameCulture)
        {
            Session["Lang"] = nameCulture;
            if(Session["GioHang"]!=null)
                {
            DataTable tb = (DataTable)Session["GioHang"];
            int i = 0;
                 foreach (DataRow dr in tb.Rows)
                {
                    cmsSanPhamDO obj = new cmsSanPhamBL().Select(new cmsSanPhamDO { SanPhamID = Int64.Parse(dr[1].ToString()) });
                    if (nameCulture.Equals("EN"))
                    {
                            dr["ThanhTien"] = double.Parse(dr["SoLuong"].ToString()) * (obj.Price * (1 - obj.GiamGia * 0.01));
                    }
                    else
                        dr["ThanhTien"] = int.Parse(dr["SoLuong"].ToString()) * (obj.DonGia * (1 - obj.GiamGia * 0.01));


                    if (i > 0)
                        dr["Sum"] = Int64.Parse(dr["Sum"].ToString()) + Int64.Parse(dr["ThanhTien"].ToString());
                    else
                        dr["Sum"] = dr["ThanhTien"];
                }
                }
            
            Response.Redirect(Request.Url.AbsolutePath.ToString());
        }
        protected void lbtnLogout_Click(object sender, EventArgs e)
        {
            Session.Abandon();
            Response.Redirect("/Default.aspx");
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (txtSearch.Text != "")
                Session["keyword"] = txtSearch.Text;
            Response.Redirect("/Search.aspx");
        }
    }
}
